package 寒假刷题;

public class 最大回文数乘积 {
    public int largestPalindrome(int n) {
         if (n==1)
             return 9;
        int max =(int)Math.pow(10, n) - 1;
        for (int i = max; i >= 0 ; i--) {
            long res = i,ans = i;
            //构造回文数
            while (ans!=0){
                res = res*10 + ans%10;
                ans/=10;
            }
            for (long j = max; j * j >= res ; j--) {
                if (res%j==0){
                    return (int)(res%1337);
                }
            }
        }
        return -1;
    }
}
